package com.user.service.impl;

import com.user.model.entity.PayInfo;
import com.user.model.entity.ServerChuZu;
import com.user.model.entity.ServerZuLin;
import com.user.model.vo.ZulinListVo;
import com.user.param.Result;
import com.user.repositories.*;
import com.user.service.PayService;
import com.user.util.GetUserUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class PayServiceImpl implements PayService {

    @Resource
    PayInfoRepository payInfoRepository;

    @Autowired
    ServerZuLinRepository serverZuLinRepository;

    @Autowired
    UserRepository userRepository;

    @Autowired
    ServerInfoRepository serverInfoRepository;

    @Autowired
    ServerChuZuRepository serverChuZuRepository;

    @Override
    public Result payInfo() {
        log.info("=======收益信息接口=======\n");
        String userId = GetUserUtil.loginUser().getId();
        List<PayInfo> payInfos = payInfoRepository.findByZuUserIdAndDeleted(userId, '1');
        List<ZulinListVo> list = new ArrayList<ZulinListVo>();
        for (PayInfo payInfo : payInfos) {
            ZulinListVo zulinListVo = new ZulinListVo();
            zulinListVo.setPayInfo(payInfo);
            zulinListVo.setUser(userRepository.findByIdAndDeleted(userId, '1'));
            zulinListVo.setServerInfo(serverInfoRepository.findByIdAndDeleted(payInfo.getServerId(), '1'));
            zulinListVo.setServerChuZu(serverChuZuRepository.findByIdAndDeleted(payInfo.getServerCzId(), '1'));
            list.add(zulinListVo);
        }

        return new Result(list);
    }
}
